--       _________ __                 __                               
--      /   _____//  |_____________ _/  |______     ____  __ __  ______
--      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
--      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \ 
--     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
--             \/                  \/          \//_____/            \/ 
--  ______________________                           ______________________
--			  T H E   W A R   B E G I N S
--	   Stratagus - A free fantasy real time strategy game engine
--      stratagus.lua - Stratagus configuration
--
--      (c) Copyright 2005 by David Stone
--
--      This program is free software; you can redistribute it and/or modify
--      it under the terms of the GNU General Public License as published by
--      the Free Software Foundation; either version 2 of the License, or
--      (at your option) any later version.
--  
--      This program is distributed in the hope that it will be useful,
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--      GNU General Public License for more details.
--  
--      You should have received a copy of the GNU General Public License
--      along with this program; if not, write to the Free Software
--      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

print("World Domination loading ...\n")

function AssignTable(tab1, tab2)
	function assign(key, value)
		tab1[key] = value
	end
	table.foreach(tab2, assign)
end

SetTitleScreens(
	{
		Image = "graphics/ui/screens/copyright_screen.png",
		Timeout = 15},
	{
		Image = "graphics/ui/screens/stratagus.png",
		Timeout = 15},
	{
		Image = "graphics/ui/screens/title_screen.png",
		Timeout = 10}

)


SetGameName("WorldDomination")
SetDefaultMap("maps/Single/Normal/test.smp")

SetVideoSyncSpeed(1000)

SetSelectionStyle("corners")
--SetShowSightRange(false)
--SetShowAttackRange(false)
--SetShowReactionRange(false)

--SetShowOrders(1)

DecorationOnTop()

DefineSprites({Name = "sprite-spell", File = "graphics/ui/game/spells.png",
			Offset = {1, 1}, Size = {16, 16}})
DefineDecorations({Index = "Bloodlust", ShowOpponent = true,
	Offset = {0, 0}, Method = {"static-sprite", {"sprite-spell", 0}}})
DefineDecorations({Index = "Haste", ShowOpponent = true,
	Offset = {16, 0}, Method = {"static-sprite", {"sprite-spell", 1}}})
DefineDecorations({Index = "Slow", ShowOpponent = true,
	Offset = {16, 0}, Method = {"static-sprite", {"sprite-spell", 2}}})
DefineDecorations({Index = "Invisible", ShowOpponent = true,
	Offset = {32, 0}, Method = {"static-sprite", {"sprite-spell", 3}}})
DefineDecorations({Index = "UnholyArmor", ShowOpponent = true,
	Offset = {48, 0}, Method = {"static-sprite", {"sprite-spell", 4}}})

--SetMetaServer("stratagus.game-host.org", 7775)
SetMetaServer("127.0.0.1", 7775)
	
DefinePlayerColorIndex(66, 4)

DefinePlayerColors({
	"red", {{164, 0, 0}, {124, 0, 0}, {92, 4, 0}, {68, 4, 0}},
	"blue", {{12, 72, 204}, {4, 40, 160}, {0, 20, 116}, {0, 4, 76}},
	"green", {{44, 180, 148}, {20, 132, 92}, {4, 84, 44}, {0, 40, 12}},
	"violet", {{152, 72, 176}, {116, 44, 132}, {80, 24, 88}, {44, 8, 44}},
	"orange", {{248, 140, 20}, {200, 96, 16}, {152, 60, 16}, {108, 32, 12}},
	"black", {{40, 40, 60}, {28, 28, 44}, {20, 20, 32}, {12, 12, 20}},
	"white", {{224, 224, 224}, {152, 152, 180}, {84, 84, 128}, {36, 40, 76}},
	"yellow", {{252, 252, 72}, {228, 204, 40}, {204, 160, 16}, {180, 116, 0}},
	"red", {{164, 0, 0}, {124, 0, 0}, {92, 4, 0}, {68, 4, 0}},
	"blue", {{12, 72, 204}, {4, 40, 160}, {0, 20, 116}, {0, 4, 76}},
	"green", {{44, 180, 148}, {20, 132, 92}, {4, 84, 44}, {0, 40, 12}},
	"violet", {{152, 72, 176}, {116, 44, 132}, {80, 24, 88}, {44, 8, 44}},
	"orange", {{248, 140, 20}, {200, 96, 16}, {152, 60, 16}, {108, 32, 12}},
	"black", {{40, 40, 60}, {28, 28, 44}, {20, 20, 32}, {12, 12, 20}},
	"white", {{224, 224, 224}, {152, 152, 180}, {84, 84, 128}, {36, 40, 76}},
	"yellow", {{252, 252, 72}, {228, 204, 40}, {204, 160, 16}, {180, 116, 0}},
})

--SetFancyBuildings(false)

SetShowTips(true)

SetXPDamage(true)
SetUseHPForXp(true)

-- this is the same as: if 1d6 is less than PiercingDamage then the unit hits and does
--	BasicDamage.  This seems to be the best way to do it right now. 

SetDamageFormula(Max(0, Mul(AttackerVar("BasicDamage"),
	GreaterThan(AttackerVar("PiercingDamage"), Rand(6)))))

SetTrainingQueue(true)

SetBuildingCapture(false)

SetRevealAttacker(true)

RightButtonMoves()

SetClickMissile("missile-green-cross")

SetDamageMissile("missile-hit")

SetGrabMouse(false)

SetLeaveStops(true)

SetMouseScroll(true)

SetKeyScroll(true)

SetKeyScrollSpeed(1)

SetMouseScrollSpeed(1)

SetMouseScrollSpeedDefault(2)

SetMouseScrollSpeedDefault(15)

SetDoubleClickDelay(300)

SetHoldClickDelay(1000)

SetShowCommandKey(true)

SetMinimapTerrain(true)

SetFogOfWar(true)
SetFogOfWarOpacity(128)
SetFogOfWarGraphics("ui/game/fog.png")

DefineDefaultResources(0, 30, 1000, 1000, 1000, 1000, 1000)
DefineDefaultResourcesLow(0, 20, 1000, 1000, 1000, 1000, 1000)
DefineDefaultResourcesMedium(0, 30, 2000, 2000, 2000, 2000, 2000)
DefineDefaultResourcesHigh(0, 40, 5000, 5000, 5000, 5000, 5000)
DefineDefaultIncomes(0, 5, 100, 100, 100, 100, 100)
DefineDefaultActions("stop", "harvest", "aquire", "drill", "mine", "mine", "mine")

DefineDefaultResourceNames("time", "crystal", "ipc", "gas", "ore", "stone", "coal")

DefineDefaultResourceAmounts("ipc", 30000, "gas", 30000)

SetSpeeds(1)

AStar("fixed-unit-cost", 1000, "moving-unit-cost", 20, "know-unseen-terrain", "unseen-terrain-cost", 2)

SetMaxSelectable(1500)

SetAllPlayersUnitLimit(500)
SetAllPlayersBuildingLimit(500)
SetAllPlayersTotalUnitLimit(1000)

function SinglePlayerTriggers()
	AddTrigger(
		function() return true end,
		function() ActionSetTimer(4000,false) ActionStartTimer() return false end)
	AddTrigger(
		function() return GetTimer() < 5 end,
		function()
		for i = 0, 15 do
		SetPlayerData(i, "Resources", "ipc", 
		(GetPlayerData(i,"Supply") + 
		GetPlayerData(i, "Resources", "ipc")))
		end
		ActionSetTimer(4000,false) return true end)
	AddTrigger(
		function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
		function() return ActionDefeat() end)
	AddTrigger(
	function() return GetNumOpponents(GetThisPlayer()) == 0 end,
	function() return ActionVictory() end)   
end



Load("preferences1.lua")
Load("preferences2.lua")

print("Loading configuration files:\n")
print("These OK-texts should help in debugging.\n")
Load("scripts/worlddomination.lua")
print("Defines: OK\n")

Load("scripts/maps.lua")
print("Maps: OK\n")

Load("scripts/icons.lua")
print("Icons: OK\n")

Load("scripts/sound.lua")
print("Sounds: OK\n")

Load("scripts/music.lua")
print("Music: OK\n")

Load("scripts/missiles.lua")
print("Missiles: OK\n")

Load("scripts/constructions.lua")
print("Constructions: OK\n")

Load("scripts/spells.lua")
print("Spells: OK\n")

Load("scripts/anim.lua")
print("Animations: OK\n")

Load("scripts/units.lua")
print("Units: OK\n")

print("Researchs: OK\n")
Load("scripts/upgrade.lua")

print("Fonts: OK\n")
Load("scripts/fonts.lua")

Load("scripts/buttons.lua")
print("Buttons: OK\n")

Load("scripts/ui.lua")
print("GUI: OK\n")

Load("scripts/ai.lua")
print("AI: OK\n")

Load("scripts/campaigns.lua")
print("Campaigns: OK\n")

Load("scripts/credits.lua")
print("Credits: OK\n")

Load("scripts/tips.lua")
print("Tips: OK\n")

Load("scripts/ranks.lua")
print("Ranks: OK\n")

Load("scripts/menus.lua")
print("Menus: OK\n")

Load("scripts/cheats.lua")
print("Cheats: OK\n")

print("Loading of scripts is complete!\n")
